package com.evil.application.pojo.dto.permission.control;

import com.evil.application.pojo.entity.ControlPermission;
import com.evil.common.application.dto.process.node.setting.NodeControlSettingDTO;
import com.evil.common.application.enums.permission.ControlVisibleEnum;
import com.evil.common.core.enums.SwitchEnum;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;

/**
 * 控件权限
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
public class ControlPermissionDTO {

    /**
     * 表单控件id
     */
    @NotNull(message = "表单控件id参数不能为空")
    private Long controlId;

    /**
     * 新增（0-否，1-是）
     */
    private Integer addStatus;

    /**
     * 编辑（0-否，1-是）
     */
    private Integer modifyStatus;

    /**
     * 删除（0-否，1-是）
     */
    private Integer deleteStatus;

    /**
     * 可见状态(0:不可见, 1:仅可见, 2:可编辑)
     */
    @NotNull(message = "可见状态参数不能为空")
    @Range(min = 0, max = 2, message = "可见状态参数错误")
    private Integer visible;

    public ControlPermissionDTO() {
        this.addStatus = SwitchEnum.YES.getId();
        this.modifyStatus = SwitchEnum.YES.getId();
        this.deleteStatus = SwitchEnum.YES.getId();
        this.visible = ControlVisibleEnum.EDIT.getId();
    }

    public ControlPermissionDTO(Long controlId) {
        this.controlId = controlId;
        this.addStatus = SwitchEnum.YES.getId();
        this.modifyStatus = SwitchEnum.YES.getId();
        this.deleteStatus = SwitchEnum.YES.getId();
        this.visible = ControlVisibleEnum.EDIT.getId();
    }

    public ControlPermissionDTO(Long controlId, Integer visible) {
        this.controlId = controlId;
        this.addStatus = SwitchEnum.YES.getId();
        this.modifyStatus = SwitchEnum.YES.getId();
        this.deleteStatus = SwitchEnum.YES.getId();
        this.visible = visible;
    }

    public ControlPermissionDTO(ControlPermission controlPermission) {
        this.controlId = controlPermission.getControlId();
        this.addStatus = controlPermission.getAddStatus();
        this.modifyStatus = controlPermission.getModifyStatus();
        this.deleteStatus = controlPermission.getDeleteStatus();
        this.visible = controlPermission.getVisible();
    }

    public ControlPermissionDTO(NodeControlSettingDTO nodeControlSettingDTO) {
        this.controlId = nodeControlSettingDTO.getControlId();
        this.addStatus = nodeControlSettingDTO.getAddStatus();
        this.modifyStatus = nodeControlSettingDTO.getModifyStatus();
        this.deleteStatus = nodeControlSettingDTO.getDeleteStatus();
        this.visible = nodeControlSettingDTO.getVisible();
    }
}
